package top.tangyh.lamp.care.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.tangyh.basic.base.R;
import top.tangyh.basic.interfaces.echo.EchoService;
import top.tangyh.basic.base.controller.SuperController;
import top.tangyh.lamp.care.service.BPipeConfigService;
import top.tangyh.lamp.care.entity.BPipeConfig;
import top.tangyh.lamp.care.vo.query.PipeConfigQueryParam;
import top.tangyh.lamp.care.vo.result.PageOutputDTO;
import top.tangyh.lamp.care.vo.result.PipeConfigGroupOutVO;
import top.tangyh.lamp.care.vo.save.BPipeConfigSaveVO;
import top.tangyh.lamp.care.vo.update.BPipeConfigUpdateVO;
import top.tangyh.lamp.care.vo.result.BPipeConfigResultVO;
import top.tangyh.lamp.care.vo.query.BPipeConfigPageQuery;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 前端控制器
 * 导管配置表
 * </p>
 *
 * @author zqb
 * @date 2024-07-19 15:02:24
 * @create [2024-07-19 15:02:24] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/channelconfig")
@Tag(name = "系统：管道管理配置")
public class BPipeConfigController  {
//    extends SuperController<BPipeConfigService, Long, BPipeConfig
//            , BPipeConfigSaveVO, BPipeConfigUpdateVO, BPipeConfigPageQuery, BPipeConfigResultVO>
//    private final EchoService echoService;
//    @Override
//    public EchoService getEchoService() {
//        return echoService;
//    }
    
    private final BPipeConfigService bPipeConfigService;


    @PutMapping()
    @Operation(summary ="新增或修改管道配置")
    public R<BPipeConfigResultVO> savePipeConfig(@RequestBody @Valid BPipeConfigSaveVO yxPipeConfigVO) {
        return R.success(bPipeConfigService.savePipeConfig(yxPipeConfigVO));
    }


    @PostMapping("/pagelist")
    @Operation(summary ="分页查询所有管道配置信息")
    public R<PageOutputDTO<BPipeConfigResultVO>> pagePipeConfig(@RequestBody @Valid PipeConfigQueryParam yxPipeConfigQueryParam) {
        return R.success(bPipeConfigService.pagePipeConfig(yxPipeConfigQueryParam));
    }


    @PostMapping("/list")
    @Operation(summary ="查询所有管道配置信息")
    public R<List<BPipeConfigResultVO>> listPipeConfig(@RequestBody(required = false)  PipeConfigQueryParam yxPipeConfigQueryParam) {
        return R.success(bPipeConfigService.queryPipeConfig(yxPipeConfigQueryParam));
    }


    @GetMapping()
    @Operation(summary ="查询单条管道配置信息")
    public R<BPipeConfigResultVO> listPipeConfig(@RequestParam("id")  Long id) {
        return R.success(bPipeConfigService.getPipeConfigOne(id));
    }

    @DeleteMapping()
    @Operation(summary ="删除管道配置信息")
    public R deletePipeConfig(@RequestParam("ids")  String ids) {
        if(StrUtil.isEmpty(ids))
        {
            return R.success();
        }
        List<Long> list = Arrays.asList(ids.split(",")).stream().map(v->Long.valueOf(v)).collect(Collectors.toList());
        if(bPipeConfigService.deletePipeConfig(list)){
            return R.success();
        }
        else{
            return R.fail("删除失败");
        }
    }

    @GetMapping("/listgroup")
    @Operation(summary ="查询所有管道配置信息")
    public R<List<PipeConfigGroupOutVO>> listPipeConfig() {
        return R.success(bPipeConfigService.queryChannelConfigGroupByPPtype());
    }

}


